package edu.xmut.kakamusic.adapter;


import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.youth.banner.adapter.BannerAdapter;

import java.util.List;

import edu.xmut.kakamusic.R;
import edu.xmut.kakamusic.bean.entity.News;
import edu.xmut.kakamusic.utils.RequestUtils;

/**
 * 自定义指示器
 */
public class ImageTitleNumAdapter extends BannerAdapter<News, ImageTitleNumAdapter.BannerViewHolder> {


    public ImageTitleNumAdapter(List<News> data) {
        super(data);
    }

    @Override
    public BannerViewHolder onCreateHolder(ViewGroup parent, int viewType) {
        View root = LayoutInflater.from(parent.getContext()).inflate(R.layout.banner_image_title_num, parent, false);
        return new BannerViewHolder(root);
    }

    @Override
    public void onBindView(BannerViewHolder holder, News data, int position, int size) {
        Glide.with(holder.bannerImage)
                .load(RequestUtils.BASE_URL + data.getImg1())
                .into(holder.bannerImage);
        holder.bannerTitle.setText(data.getNewsName());
        holder.numIndicator.setText(String.format("%d/%d", position + 1, size));
    }


    public class BannerViewHolder extends RecyclerView.ViewHolder {
        public final ImageView bannerImage;
        public final TextView bannerTitle;
        public final TextView numIndicator;

        public BannerViewHolder(@NonNull View view) {
            super(view);
            bannerImage = view.findViewById(R.id.banner_image);
            bannerTitle = view.findViewById(R.id.banner_title);
            numIndicator = view.findViewById(R.id.num_indicator);
        }
    }
}
